package com.iamteer.cupband;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


public class BondingAfterFragment extends Fragment {
    private Button btnDisconnect;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_bonding_after, container, false);

        btnDisconnect = (Button) root.findViewById(R.id.btnDisconnect);

        BondingActivity.swBondingEnable.setEnabled(false);
        BondingActivity.swBondingEnable.setAlpha(0.4f);

        btnDisconnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (MainActivity.mDevice != null) {
                    MainActivity.mService.disconnect();
                    MainActivity.mState = MainActivity.UART_PROFILE_DISCONNECTED;

                    getFragmentManager().beginTransaction()
                            .replace(R.id.fragment, new BondingFragment())
                            .commit();

                    BondingActivity.swBondingEnable.setEnabled(true);
                    BondingActivity.swBondingEnable.setAlpha(1.0f);
                }
            }
        });


        return root;
    }
}
